package com.example.springboot.config.anotation.parametervalidate;

import cn.hutool.core.collection.CollUtil;
import org.springframework.stereotype.Component;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.List;

/**
 * 注解解析器
 *
 * @author chenzhangkun
 * @ClassName ArrayNotNullAndEmptyValidator
 * @description: TODO
 * @date 2024年04月25日
 */
@Component
public class ArrayNotNullAndEmptyValidator implements ConstraintValidator<ArrayNotNullAndEmptyStr, List<String>> {
	@Override
	public void initialize(ArrayNotNullAndEmptyStr constraintAnnotation) {
		ConstraintValidator.super.initialize(constraintAnnotation);
	}

	@Override
	public boolean isValid(List<String> strings, ConstraintValidatorContext constraintValidatorContext) {
		if (CollUtil.isEmpty(strings)) {
			return false;
		}
		if (strings.stream().allMatch(""::equals)) {
			return false;
		}
		return true;
	}
}
